package com.cx.model.ai.util;

import com.alibaba.fastjson.JSONObject;
import com.cx.model.ai.entity.Chat;
import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.RequestBody;

/**
 * @program: pms
 * @author: cx
 * @description:
 * @create: 2025-03-19 14:23
 **/
public class Const {

    private static final String CONTENT_TYPE = "application/json";

    private static final String AUTHORIZATION = "Bearer ";






    /**
     * 构建HTTP请求
     * @param object   请求体对象，会被转换为JSON字符串
     * @param apiUrl   API地址
     * @param method   请求方法（如 "POST"、"GET"）
     * @return 构建好的Request对象
     * @throws IllegalArgumentException 如果媒体类型或请求体创建失败
     */
    public static Request buildHttpRequest(Object object, String apiUrl, String method) {
        try {
            // 定义请求体的媒体类型
            MediaType mediaType = MediaType.parse(CONTENT_TYPE);
            // 创建请求体，将对象转换为JSON字符串
            RequestBody body = RequestBody.create( JSONObject.toJSONString(object),mediaType);
            // 构建并返回Request对象
            return new Request.Builder()
                    .url(apiUrl)
                    .method(method, body)
                    .addHeader("Content-Type", CONTENT_TYPE)
                    .addHeader("Accept", CONTENT_TYPE)
                    .addHeader("Authorization", AUTHORIZATION+"3GCFCQG-5DEMX1Z-HG9MRJE-CN8KQNH")
                    .build();
        } catch (Exception e) {
            throw new IllegalArgumentException("构建HTTP请求失败", e);
        }
    }



}